#!/usr/bin/env bash
# Small helper script to render single example / tutorials.
if [[ $# -eq 0 ]] ; then
    echo "Usage: render_example tutorial_or_example.py"
    echo "This script takes no arguments."
    exit 0
fi

dirname=$(dirname $1)
filename=$(basename -s .py $1)
tmpfolder=$(mktemp -d)
cwd=$(pwd)

sphx_glr_python_to_jupyter.py $1 && mv "${dirname}/${filename}.ipynb" $tmpfolder
echo "Executing in temporary folder $tmpfolder."
cd $tmpfolder
jupyter nbconvert --log-level="INFO" --execute --to html "${filename}.ipynb"
mv "${filename}.html" $cwd && echo "Moved ${filename}.html to ${cwd} and deleted ${tmpfolder}. DONE."
rm -rf $tmpfolder
echo "Try to open in FireFox"
cd $cwd && firefox ${filename}.html
